package com.aj.controller;

import com.aj.common.MessageConstant;
import com.aj.pojo.CheckItem;
import com.aj.utils.SMSUtils;
import com.aj.utils.ValidateCodeUtils;
import com.alibaba.dubbo.config.annotation.Reference;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.JedisPool;

@RestController
@RequestMapping("/validateCode")
public class ValidateCodeController {


    @Autowired
    private JedisPool jedisPool;


    @RequestMapping("/send4Order")
    public Result send4Order(String telephone) {
        Integer parm = ValidateCodeUtils.generateValidateCode(6);
        try {
//            SMSUtils.sendShortMessage(SMSUtils.VALIDATE_CODE,telephone , parm.toString());
            jedisPool.getResource().setex(telephone,60*5 , parm.toString());
            System.out.println(parm);
            return new Result(true, MessageConstant.SEND_VALIDATECODE_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.SEND_VALIDATECODE_FAIL);
        }
    }
}
